﻿#region File Header
//-----------------------------------------------------------------------------
// SibLib
//
// Copyright (C) 2010 Julien Villers
// This program is distributed under the terms of the 
// GNU Lesser General Public License (LGPL).
// See Docs/lgpl.txt and Docs/gpl.txt
//
// This file is based on a XNAWiki page.
//-----------------------------------------------------------------------------
#endregion

using Microsoft.Xna.Framework;

namespace SibLib
{
    /// <summary>
    /// This class is a container for extension methods of classes representing geometric data (coordinates, sizes, etc).
    /// </summary>
    public static class GeometryExtensions
    {
        #region Vector2
        public static Point ToPoint(this Vector2 v)
        {
            return new Point((int)v.X, (int)v.Y);
        }

        public static Vector3 ToVector3(this Vector2 v)
        {
            return new Vector3(v.X, v.Y, 0.0f);
        }
        #endregion

        #region Rectangle
        public static Point BottomRightAsPoint(this Rectangle r)
        {
            return new Point(r.Right, r.Bottom);
        }

        public static Vector2 BottomRightAsVector2(this Rectangle r)
        {
            return new Vector2(r.Right, r.Bottom);
        }

        public static bool Contains(this Rectangle r, float x, float y)
        {
            return x >= r.X && x <= r.X + r.Width && y >= r.Y && y <= r.Y + r.Height;
        }

        public static bool Contains(this Rectangle r, Vector2 pos)
        {
            return pos.X >= r.X && pos.X <= r.X + r.Width && pos.Y >= r.Y && pos.Y <= r.Y + r.Height;
        }

        public static Rectangle FromLTRB(this Rectangle src, float left, float top, float right, float bottom)
        {
            return new Rectangle(src.X, src.Y, src.Right - src.X, src.Bottom - src.Y);
        }

        #endregion
    }
}
